package com.ccsoft.atools.service;

import com.ccsoft.atools.dao.GBill01Mapper;
import com.ccsoft.atools.dao.GBilldetail01Mapper;
import com.ccsoft.atools.model.GBill01;
import com.ccsoft.atools.model.GBilldetail01;
import com.ccsoft.atools.utils.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName:MigrateCashService
 * @Description:迁移现金日记账的数据，从表 G_Bill01、G_BillDetail01 到 cash_main,cash_detail
 * @Author:chanchaw
 * @Date:2020-01-18 8:26
 * @Version:1.0
 **/
public class MigrateCashService {
    @Autowired
    private GBill01Mapper main;

    @Autowired
    private GBilldetail01Mapper detail;

    public void migrate() {
        List<GBill01> listMain = main.selectAll();
        if (listMain.size() <= 0) {
            throw BusinessException.instance("主表数据为空，无法迁移！");
        }

        List<ErrorTip> listTip = new ArrayList<>();
        for (GBill01 item : listMain) {
            List<GBilldetail01> listDetail = detail.selectByFK(item.getB_ID());
            if (listDetail.size() <= 0) {
                listTip.add(new ErrorTip(item.getB_ID(), item.getB_CodeID()));
            } else {
                // 1. 构建主表对象，等待写入

                // 2. 构建明细表对象集合，等待写入
            }
        }
    }


    private class ErrorTip {
        private int b_ID;
        private String b_CodeId;

        public ErrorTip(int b_ID, String b_CodeId) {
            this.b_CodeId = b_CodeId;
            this.b_ID = b_ID;
        }
    }
}


